<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2014 Bauer-Live Softwaredevelopment.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
             
                xmlns:p="http://primefaces.org/ui"
                xmlns:hf="http://highfaces.org"

                template="/WEB-INF/master.xhtml"
                >
    <ui:define name="headline">ChartModel API - Define your series in code</ui:define>
    <ui:define name="description">If you prefer defining your series in code rather than declaring them in xhtml, you can use the ChartModel API with either the default implementations or even implement the interfaces on your own classes.</ui:define>
    
    <ui:define name="icontent">
        
        <h:panelGroup layout="block">
            <hf:chart type="column" model="#{chartModelBean.model}"  title="Defined series via ChartModel API"/>            
        </h:panelGroup>
    </ui:define>
    <ui:define name="xhtml">
        <script type="syntaxhighlighter" class="brush: xml"><![CDATA[
            
               <hf:chart type="column" model="# {chartModelBean.model}"  title="Defined series via ChartModel API"/> 

            ]]></script>
    </ui:define>
    <ui:define name="java">        
        <script type="syntaxhighlighter" class="brush: java"><![CDATA[
@ManagedBean
@RequestScoped
public class ChartModelBean {

    protected DefaultChartModel model;

    public ChartModelBean() {
        reload();
    }

    public void reload() {
        model = new DefaultChartModel();
        DefaultChartSeries boysSeries = new DefaultChartSeries();
        DefaultChartSeries girlsSeries = new DefaultChartSeries();
        boysSeries.setName("Boys");
        girlsSeries.setName("Girls");
        
        Random r = new Random();
        for (int i = 2000; i < 2010; i++) {
            boysSeries.addPoint(Integer.toString(i), r.nextInt(500) + 800);
            girlsSeries.addPoint(Integer.toString(i), r.nextInt(500) + 800);
        }
        model.getSeries().add(boysSeries);
        model.getSeries().add(girlsSeries);
    }

    public ChartModel getModel() {
        return model;
    }

}
        ]]></script>
    </ui:define>
</ui:composition>